import random

WIDTH = 250
HEIGHT = 250

BACK_COLOR = (0, 0, 0)

STEP_COLOR = 10
CUR_COLOR = 10

unit = 50

a = [
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0],
]

class MyRect:
    def __init__(self, x, y, w, h, clr):
        self.x = x
        self.y = y
        self.clr = clr
        
    def Update(self):
        pass

    def Draw(self):
        rc = Rect((self.x - unit // 2, self.y - unit // 2), (unit, unit))
        screen.draw.filled_rect(rc, self.clr)

rc_list = []
unit = 50
def reset():
    global CUR_COLOR
    global STEP_COLOR
    global a
    x = 0
    y = 0
    count = 25
    a[x][y] = CUR_COLOR
    CUR_COLOR += STEP_COLOR

    count -= 1
    while count > 0:
        while x + 1 < 5 and a[x + 1][y] == 0:
            x += 1
            a[x][y] = CUR_COLOR
            CUR_COLOR += STEP_COLOR
            count -= 1

        while y - 1 >= 0 and a[x][y - 1] == 0:
            y -= 1
            a[x][y] = CUR_COLOR
            CUR_COLOR += STEP_COLOR
            count -= 1

        while x - 1 >= 0 and a[x - 1][y] == 0:
            x -= 1
            a[x][y] = CUR_COLOR
            CUR_COLOR += STEP_COLOR
            count -= 1

        while y + 1 < 5 and a[x][y + 1] == 0:
            y += 1
            a[x][y] = CUR_COLOR
            CUR_COLOR += STEP_COLOR
            count -= 1

    for r in range(0, 5):
        for c in range(0, 5):
            rc = MyRect(r * unit + unit // 2, c * unit + unit // 2, unit, unit, (a[r][c], 0, 0))
            rc_list.append(rc)

reset()

def on_key_down(key):
    if key == keys.ESCAPE:
        quit()
    elif key == keys.SPACE:
        reset()
        
def on_mouse_down(pos):
    print("mouse_down", pos)

def on_mouse_up(pos):
    print("mouse_up", pos)
    
def update():
    pass
        
def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    for rc in rc_list:
        rc.Draw()